import 'package:flutter/material.dart';
import 'package:jiaju_flutter/widgets/image/comm_image.dart';

class IndexNavigator extends StatelessWidget {
  final List<IndexNavigatorItem> itemList;
  final Function(int index) onTap;

  const IndexNavigator({Key key, this.itemList, this.onTap}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: itemList
              .asMap()
              .entries
              .map(
                (e) => InkWell(
                  onTap: () => onTap(e.key),
                  child: Container(
                    padding: EdgeInsets.all(10),
                    child: Column(
                      children: [
                        CommImage(
                          e.value.image,
                          width: 40,
                          height: 40,
                        ),
                        Text(e.value.text),
                      ],
                    ),
                  ),
                ),
              )
              .toList()),
    );
  }
}

class IndexNavigatorItem {
  String text;
  String image;

  IndexNavigatorItem(this.text, this.image);
}
